package com.situ.blog.service.impl;

import com.situ.blog.dao.IUserDao;
import com.situ.blog.dao.impl.UserDaoImpl;
import com.situ.blog.pojo.User;
import com.situ.blog.service.IUserService;
import com.situ.blog.util.JSONResult;
import com.situ.blog.util.LayUITableJSONResult;

import java.util.List;

public class UserServiceImpl implements IUserService {
    private IUserDao userDao = new UserDaoImpl();

    @Override
    public LayUITableJSONResult selectByPage(Integer page, Integer limit) {
        int offset = (page - 1) * limit;
        List<User> list = userDao.selectByPage(offset, limit);
        int totalCount = userDao.selectTotalCount();

        return LayUITableJSONResult.ok(totalCount, list);
    }

    @Override
    public JSONResult add(User user) {
        int count = userDao.add(user);
        return count == 1 ? JSONResult.ok("添加成功") : JSONResult.error("添加失败");
    }

    @Override
    public JSONResult updateStatus(int id, int status) {
        int count = userDao.updateStatus(id, status);
        return  count == 1 ? JSONResult.ok("修改状态成功") : JSONResult.error("修改状态失败");
    }

    @Override
    public User login(String name, String password) {
        return userDao.login(name, password);
    }

}
